import type { Metadata } from 'next';
import { Geist, Geist_Mono } from 'next/font/google';
import { setRequestLocale } from 'next-intl/server';
import type { ReactNode } from 'react';
import { isRTL, type Locale, locales } from '@/i18n';
const geistSans = Geist({
variable: '--font-geist-sans',
subsets: ['latin'],
});
const geistMono = Geist_Mono({
variable: '--font-geist-mono',
subsets: ['latin'],
});
export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};
// Pre-generate static pages for all locales at build time (SSG)
// This improves performance and SEO
export function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}
export default async function LocaleLayout({
children,
params,
}: {
children: ReactNode;
params: Promise<{ locale: Locale }>;
}) {
// In Next.js App Router, params is a Promise (can be await'd)
// This allows for dynamic route segments to be resolved asynchronously
const { locale } = await params;
// Critical: setRequestLocale tells next-intl which locale to use for this request
// Without this, getTranslations() won't know which locale to use in server components
setRequestLocale(locale);
return (
<html lang={locale} dir={isRTL(locale) ? 'rtl' : 'ltr'}>
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}